package com.ctl.szmd.szmd.feature_wm.ui.adapter.wm

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.ctl.lib_common.base.mvvm.DataBindingViewHolder
import com.ctl.szmd.szmd.feature_wm.R
import com.ctl.szmd.szmd.feature_wm.data.model.WmDataListModel
import com.ctl.szmd.szmd.feature_wm.databinding.WmBannerHomeBinding
import com.ctl.szmd.szmd.utils.ext.doWithTry

import com.youth.banner.adapter.BannerAdapter

/**
 * created by : chentl
 * Date: 2020/07/29
 */
class WmBannerHomeAdapter(val data: List<WmDataListModel>) :
    BannerAdapter<WmDataListModel, BannerViewHolder>(data) {

    override fun onCreateHolder(parent: ViewGroup, viewType: Int): BannerViewHolder {
        val view =
            LayoutInflater.from(parent.context).inflate(R.layout.wm_banner_home, parent, false)
        return BannerViewHolder(view)
    }

    override fun onBindView(
        holder: BannerViewHolder?,
        data: WmDataListModel?,
        position: Int,
        size: Int
    ) {
        doWithTry {
            data?.let {
                holder?.bindData(data, position)
            }
        }
    }
}

class BannerViewHolder(view: View) :
    DataBindingViewHolder<WmDataListModel>(view) {
    private val mBinding: WmBannerHomeBinding by viewHolderBinding(view)
    override fun bindData(data: WmDataListModel, position: Int) {
        mBinding.apply {
            model = data
            executePendingBindings()
        }
    }
}